import os
from datetime import timedelta
from .config_manager import config_manager

class Config:
    """应用配置类"""
    
    def __init__(self):
        # 从配置管理器获取配置
        self.SECRET_KEY = config_manager.get_secret_key()
        self.DEBUG = config_manager.get_server_debug()
        
        # 文件上传配置
        self.MAX_CONTENT_LENGTH = config_manager.get_max_file_size()
        self.UPLOAD_FOLDER = config_manager.get_upload_folder()
        self.TEMP_FOLDER = config_manager.get_temp_folder()
        
        # 支持的文件格式
        self.ALLOWED_EXTENSIONS = config_manager.get_allowed_extensions()
        
        # 转换选项
        self.CONVERSION_TIMEOUT = config_manager.get_conversion_timeout()
        
        # 文件清理配置
        self.TEMP_FILE_LIFETIME = config_manager.get_temp_file_lifetime()
    
    @staticmethod
    def init_app(app):
        """初始化应用配置"""
        # 确保上传和临时目录存在
        os.makedirs(config_manager.get_upload_folder(), exist_ok=True)
        os.makedirs(config_manager.get_temp_folder(), exist_ok=True)

class DevelopmentConfig(Config):
    """开发环境配置"""
    def __init__(self):
        super().__init__()
        self.DEBUG = True

class ProductionConfig(Config):
    """生产环境配置"""
    def __init__(self):
        super().__init__()
        self.DEBUG = False

class TestingConfig(Config):
    """测试环境配置"""
    def __init__(self):
        super().__init__()
        self.TESTING = True
        self.WTF_CSRF_ENABLED = False

config = {
    'development': DevelopmentConfig,
    'production': ProductionConfig,
    'testing': TestingConfig,
    'default': DevelopmentConfig
} 